BookForm = Ext.extend(Ext.Window,{
	formPanel : null,
	imgFormPanel:null,
	constructor : function(a) {
		Ext.applyIf(this, a);
		this.initUIComponents();
		BookForm.superclass.constructor.call(this, {
			layout : "fit",
			items : [this.formPanel],
			border : false,
			modal : true,
			plain : true,
			id : "BookFormWin",
			title : "书籍信息",
			iconCls : "menu-role",
			width : document.body.clientWidth - 300,
			height : document.body.clientHeight,
			bodyStyle : "padding:5px;",
			buttonAlign : "center",
			buttons : this.buttons
		});
	},
	initUIComponents : function() {
		var storeAuthor = new Ext.data.Store ({
				proxy: new Ext.data.HttpProxy({url:__ctxPath + "/system/searchAutorUser.do"}), // 数据源               
				reader: new Ext.data.JsonReader({totalProperty:"totalPorperty",root:"result",fields:[{name: 'id'},{name: 'name'}]})// 如何解析
		}); 
		this.formPanel = new Ext.FormPanel( {
			enctype: 'multipart/form-data',  
			fileUpload : true, 
			url : __ctxPath + "/saveBook.do",
			id : "BookForm",
			autoHeight : true,  
			frame : true,  
			renderTo : Ext.getBody(),  
			layout : "form", // 整个大的表单是form布局  
			labelWidth : 55,  
			labelAlign : "center",  
			items:[{  
				xtype:"panel",    
				baseCls:"x-plain",  
				layout:"column",  
				items:[{  
					columnWidth:.5,  
					layout:"form",  
					labelWidth:55,  
					baseCls:"x-plain",
					items:[ 
						{name : "book.id",id : "id",xtype : "hidden",value : this.id == null ? "" : this.id},
						{name : "book.pto",id : "pto",xtype : "hidden"},
						{name : "book.electronic",id : "electronic",xtype : "hidden"},
						{name:"book.type",id:"type",xtype : "hidden"},
						{name:"book.author",id:"author",xtype : "hidden"},
						{name:"book.name",id:"name",fieldLabel:"书名",xtype:"textfield",anchor : '90%',allowBlank:true,maxLength:'20'}, 
						{fieldLabel:"作者",allowBlank:true,id:"authorName",
							items:[
							   new Ext.form.ComboBox ({    
								   tpl: '<tpl for="."><div ext:qtip="提示：id={id}；TypeCName={name}" class="x-combo-list-item">{name}</div></tpl>',
									editable:true,//默认为true，false为禁止手写和联想功能
									store:storeAuthor,
									emptyText:'请选择',
									mode: 'remote',//指定数据加载方式，如果直接从客户端加载则为local，如果从服务器断加载 则为remote.默认值为：remote
									triggerAction: 'all',
									valueField:'id',
									displayField:'name',
									hiddenName:'auhorName',
									selectOnFocus:true,
									anchor : '95%',
									border:true,
									frame:true,
									resizable:true,
									pageSize:6,
									minChars:1,
									id:"book-author-combox",
									listeners:{
										"select":function(){
											var author_id = Ext.getCmp('BookForm').getForm().findField('auhorName').getValue();
											Ext.getCmp("BookForm").getForm().setValues( { 'author' :author_id} );  
											}
									}
								})
						   ]
						},  
						{name:"book.translator",id:"translator",fieldLabel:"译者",xtype:"textfield",anchor : '90%'},
						{name:"book.publishing",id:"publishing",fieldLabel:"出版社",xtype:"textfield",anchor : '90%' },
						{name:"book.publishingDateStr",id:"publishingDateStr",fieldLabel:"出版时间",xtype:"datefield",format:"Y-m-d",anchor : '90%'},
						{name:"book.isbn",id:"isbn",fieldLabel:"图书编号",xtype:"textfield",anchor : '90%'},
						{name:"book.price",id:"price",fieldLabel:"图书定价",xtype:"textfield",anchor : '90%'},
						{name:"book.pageCount",id:"pageCount",fieldLabel:"页数",xtype:"textfield",anchor : '90%'},
						{name:"book.binding",id:"binding",fieldLabel:"装帧",xtype:"textfield",anchor : '90%'},
						{fieldLabel:"书籍类型",id:"typeName",
							items:[
							   new XIINN.ui.ComboBoxTree({  
									treeUrl: __ctxPath + '/comboxTreeBookType.do?parentid=',
									editable:false,  
									rootText:"书籍分类", 
									rootId:'0',
									valueField:"com",  
									displayField:"_com",  
									id:"book-type-combox",
									callback:function(combox,node){  
										if(node.leaf){
											combox.setValue(node.text);  
											Ext.getCmp("BookForm").getForm().setValues( { 'type' :node.id} );  
											combox.collapse();
										}
										//可以做更多的处理。 
									}  
								})
							]
						}
					]  
				},{ 
					columnWidth:.5,  
					layout:"form",      
					items:[{
						xtype: 'fieldset',
						id: 'view-file',
						fieldLabel: '封面预览',
						name: 'view-file',
						height:200,
						anchor : '70%',
						items : [{
							height:200,
							xtype: 'box', //或者xtype: 'component',  
							anchor : '100%', //图片宽度  
							id:'imgView',
							autoEl: {  
								tag: 'img',    //指定为img标签  
								src: __ctxPath+'/default_pto.jpg'    //指定url路径  
							}  
						}]
					}]      
				 }  
			  ]               
		   },{ xtype : "htmleditor",  
				fieldLabel : "书籍简介",  
				name:"book.bookSynopses",
				id:"bookSynopses",
				anchor : '100%',
				allowBlank:true,
				height : document.body.clientHeight-400
				
		   },{
				anchor : '95%',
				xtype: 'fileuploadfield',
				id: 'filePath',
				emptyText: '请选择一张图片',
				fieldLabel: '封面',
				name: 'filePto',
				buttonText: '浏览'
			},{
				anchor : '95%',
				xtype: 'fileuploadfield',
				id: 'bookFilePath',
				emptyText: '请选择电子书籍',
				fieldLabel: '电子版',
				name: 'fileElectronic',
				buttonText: '浏览'
			}]
		});
		if (this.id != null && this.id != "undefined") {
			this.formPanel.getForm().load({
				deferredRender : false,
				url : __ctxPath
						+ "/getBook.do?id="
						+ this.id,
				waitMsg : "正在载入数据...",
				success : function(a, b) {
					var src = __ctxPath+"/default_pto.jpg";
					if(b.result.data.pto!=null &&　b.result.data.pto!=""){
						src = __ctxPath+'/upload/'+b.result.data.pto;
					}
					Ext.getCmp("imgView").getEl().dom.src=src;
					Ext.getCmp("book-type-combox").setValue( b.result.data.typeName); 
					Ext.getCmp("book-author-combox").setValue( b.result.data.authorName);  
				},
				failure : function(a, b) {}
			});
		}
		this.buttons = [{
			text : "提交",
			iconCls : "btn-save",
			handler : function() {
				var b = Ext.getCmp("BookForm");
				if (b.getForm().isValid()) {
					b.getForm().submit({
						method : "post",
						waitMsg : "正在提交数据...",
						success : function(c,d) {
							Ext.ux.Toast.msg("操作信息","成功信息保存！");
							Ext.getCmp("BookGrid").getStore().reload();
							var src = __ctxPath+"/default_pto.jpg";
							if(d.result.data.pto!=null &&　d.result.data.pto!=""){
								src = __ctxPath+'/upload/'+d.result.data.pto;
							}
							Ext.getCmp("imgView").getEl().dom.src=src;
							//Ext.getCmp("BookFormWin").close();
						},
						failure : function(c,d) {
							Ext.MessageBox.show( {
								title : "操作信息",
								msg : "信息保存出错，请联系管理员！",
								buttons : Ext.MessageBox.OK,
								icon : "ext-mb-error"
							});
							//Ext.getCmp("BookFormWin").close();
						}
					});
				}
			}
		}, {
			text : "取消",
			iconCls : "btn-cancel",
			handler : function() {
				Ext.getCmp("BookFormWin").close();
			}
		} ];
	}
});

